package com.blog.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import com.blog.pojo.Member;
import com.blog.service.MemberService;

/** 
 * @author ant 
 * @date 创建时间：2017年8月16日 下午4:41:07  
 */
@Component
public class CustomUserDetailsService implements UserDetailsService {

	@Autowired
	private MemberService memberService;
	
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		Member member = memberService.findMemberByLoginName(username);
		if (member == null) {
			throw new UsernameNotFoundException("UserName " + username + " not found");
		}
		SecurityUser securityUser = new SecurityUser(member);
		return securityUser;
	}

}
